
function [] = test_min_ts()

amiga_model1 = 'a500 winuae';
amiga_model2 = 'a500';
filter_mode = 'led filter off';
spectrum_cut = get_spectrum_cut();
fs = get_sampling_fq();

ts = get_amiga_filter_ts(amiga_model1, filter_mode);

[k1, t] = firwin(amiga_model1, fs, spectrum_cut, 2048, false);
k2 = fir_min_phase(k1);

wblip = get_blip(amiga_model2, filter_mode, 'winuae');
wblep = get_blep(wblip);

tsblip1 = lsim(ts, k1', t');
tsblip1 = tsblip1';
tsblip1 = fir_min_phase(tsblip1);
tsblep1 = step_calc(tsblip1);

tsblip1a = fir_min_phase(tsblip1);
assert(error_calc(tsblip1, tsblip1a) < 1e-10);

tsblip2 = lsim(ts, k2', t');
tsblip2 = tsblip2';
tsblep2 = step_calc(tsblip2);

tsblip3 = fir_min_phase(tsblip2);
tsblep3 = step_calc(tsblip3);

TSF1 = abs(fft(tsblip1, fs));
TSF2 = abs(fft(tsblip2, fs));
TSF3 = abs(fft(tsblip3, fs));
WF = abs(fft(wblip, fs)); 
TSF1 = TSF1(1:1:30000);
TSF2 = TSF2(1:1:30000);
TSF3 = TSF3(1:1:30000);
WF = WF(1:1:30000);
fx = (1:1:30000);

S1a = get_spice_fq(amiga_model2, filter_mode);
S1a = abs(S1a);
S1a = [S1a(1:1:22050), zeros(1, 30000 - 22050)];

figure(1);
hold on;
title('time blep');
plot(t, tsblep1, 'r');
plot(t, tsblep3, '.');
plot(t, tsblep2, 'g');
plot(t, wblep, 'b');
title('comparison in time');
legend('fir-lsim-min-blep', 'fir-min-lsim-min-step', 'fir-min-lsim-step', 'winuae');

figure(2);
hold on;
title('lin fq');
plot(fx, TSF1, 'r');
plot(fx, TSF3, '.');
plot(fx, TSF2, 'g');
plot(fx, WF, 'b');
plot(fx, S1a, 'c');
title('comparison in freq');
legend('fir-lsim-min-blep', 'fir-min-lsim-min-step', 'fir-min-lsim-step', 'winuae', 'spice fq');

figure(3);
hold on;
title('log fq');
plot(log(fx), 20*log(TSF1), 'r');
plot(log(fx), 20*log(TSF3), '.');
plot(log(fx), 20*log(TSF2), 'g');
plot(log(fx), 20*log(WF), 'b');
plot(log(fx), 20*log(S1a), 'c');
legend('fir-lsim-min-blep', 'fir-min-lsim-min-step', 'fir-min-lsim-step', 'winuae', 'spice fq');

end